<template>
    <j-modal title="系统状态" :width="680" :visible="visible" :confirmLoading="confirmLoading" switchFullscreen
        @ok="handleSubmit" @cancel="handleCancel" cancelText="关闭">
        <a-spin :spinning="confirmLoading">
            <a-form>
                <a-form-item label="系统状态" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 8px;">
                    <a-radio-group name="disabledStatus" :default-value="model.disabledStatus"
                        v-model="parmas.disabledStatus">
                        <a-radio :value="0">
                            启用
                        </a-radio>
                        <a-radio :value="1">
                            禁用
                        </a-radio>
                    </a-radio-group>
                </a-form-item>

                <a-form-item label="禁用时间" required :labelCol="labelCol" :wrapperCol="wrapperCol"
                    v-if="!!parmas.disabledStatus">
                    <a-date-picker format="YYYY-MM-DD" placeholder="请选择禁用时间" @change="onChange" />
                </a-form-item>
            </a-form>
            <a-divider style="margin: 10px 0;"/>

            <div style="font-weight: 600;margin-bottom: 10px;">操作日志:</div>
            <section style="max-height: 500px;overflow-y: auto;">
                <p v-for="item,index in reocrdList" >
                    {{ item.content }} 
                </p>
            </section>
            <p v-if="!reocrdList.length">暂无数据</p>
        </a-spin>
    </j-modal>
</template>

<script type="text/ecmascript-6">
import { httpAction, getAction } from "@api/manage";

export default {
    name: "StmEditSales",
    data() {
        return {
            visible: false,
            confirmLoading: false,
            model: {},

            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 },
            },
            url: {
                updateDisabledStatus: 'stm/stmStoreInfo/updateDisabledStatus',
                reocrdList: 'stm/stmStoreInfoTrace/list',
            },
            parmas: {
                disabledTime: null,
                disabledStatus: 0 // 0.否 1.是
            },
            reocrdList: []
        }
    },
    methods: {
        show(record) {
            this.visible = true;
            this.model = record;
            this.parmas = {
                disabledTime: record.disabledTime,
                disabledStatus: record.disabledStatus
            }
            this.reocrdList = []
            this.getRecordsList()
        },
        close() {
            this.$emit('close');
            this.visible = false;
        },
        getRecordsList() {
            getAction(this.url.reocrdList,{storeId:this.model.storeId,pageNum:1,pageSize:300}).then((res) => {
                if (res.success) {
                    this.reocrdList = res.result.records;
                }
            })
        },
        onChange(value, dateString) {
            this.parmas.disabledTime = dateString + ' 00:00:00'
        },
        handleSubmit() {
            if (this.parmas.disabledStatus == 1 && !this.parmas.disabledTime) {
                this.$message.warning('请选择禁用时间');
                return;
            }
            if (this.parmas.disabledStatus == 0) {
                this.parmas.disabledTime = null
            }
            httpAction(this.url.updateDisabledStatus,{
                id:this.model.storeId,
                ...this.parmas
            } , "post").then((res) => {
                if (res.success) {
                    this.$message.success(res.message);
                    this.$emit('ok');
                } else {
                    this.$message.warning(res.message);
                }
            }).finally(() => {
                this.confirmLoading = false;
                this.close();
            });
        },
        handleCancel() {
            this.close()
        },
    }
}
</script>
<style lang="less" scoped></style>